"==
"== editor behavior
"==
set mouse=a                                              " 使用鼠标
"set textwidth=80                                         " 设置行宽
set nocompatible                                          " 关闭兼容模式
set hidden
set noerrorbells                                          " vim 错误不报错
set visualbell t_vb=
set helplang=cn                                           " 中文文档
set ttyfast                                               " should make scrolling faster
set nu                                                    " 设置行号
set relativenumber                                        " 相对行好
set wrap                                                  " 自动折行
set scrolloff=7                                           " 在上下移动光标时，光标的上方或下方至少会保留显示的行数
set t_Co=256                                              " 终端显示256色
set termguicolors
set showmode                                              " 显示当前mode
set showtabline=2                                         " 显示当前tab
set laststatus=2
set autoread                                              " 自动加载文件的变化
set spelllang=en_us                                       " 英语单词拼写检查
set tabpagemax=15                                         " 最多15个Tab
"set clipboard=unnamed                                    " 系统剪贴板
"set clipboard=unnamedplus                                 "寄存器使用系统剪贴板
set history=2000                                          " history存储容量
set timeoutlen=500                                        " 等待时间,如<leader>键后的输入
set list                                                  " 显示特殊符号
set listchars=tab:\|\ ,trail:▫
syntax on                                                 " 关键字上色
syntax enable                                             " 语法高亮
set autochdir                                             " 自动切换到文件所在文件夹
autocmd BufWritePost $MYVIMRC source $MYVIMRC             " 自动加载vimrc
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936  " 设置编码
set termencoding=utf-8
set encoding=utf-8
filetype on                                               " 打开文件类型检测
filetype indent on
filetype plugin on
filetype plugin indent on
set fileformat=unix
set wildmenu                                              " 命令模式下补全以菜单形式显示
"set wildmode=list,longest,full                           " 命令模式补全模式
set incsearch                                             " 边输入边搜索
set ignorecase                                            " 搜索忽略大小写
set smartcase                                             " 智能大小写搜索
autocmd BufEnter * silent! lcd %:p:h                      " 自动将目录改为当前目录
set splitright                                            " 新分割窗口在右边
set splitbelow                                            " 新分割窗口在下边
set tabstop=4                                             " tab缩进4个空格
set shiftwidth=4                                          " 自动缩进空格数
set softtabstop=4                                         " 退格删除缩进
set autoindent                                            " 与前一行同样等级缩进
set expandtab                                             " tab转为空格





"==
"== 设置键位
"==
let mapleader="\<space>"
noremap <c-z> <nop>
noremap s <nop>
nnoremap Q <Cmd>call VSCodeNotify('workbench.action.closeActiveEditor')<CR>
nnoremap W <Cmd>call VSCodeNotify('workbench.action.files.save')<CR>
" Press <SPACE> + q to close the window below the current window
noremap <LEADER>q <C-w>j:q<CR>
noremap U <C-r>
noremap u :u<CR>
nnoremap ; :
vnoremap ; :
inoremap jj <Esc>
noremap H ^
nnoremap L g_
vnoremap L g_
vmap q <esc>
nnoremap <leader>w W
nnoremap <leader>e E
nnoremap <leader>b B
nnoremap E <Cmd>call VSCodeNotify('workbench.action.previousEditor')<CR>
nnoremap R <Cmd>call VSCodeNotify('workbench.action.nextEditor')<CR>


"光标行移动
nnoremap k gk
nnoremap gk k
nnoremap j gj
nnoremap gj j
"ctrl j,ctrl k,上下移动5行
noremap <C-j> 5j
noremap <C-k> 5k


"alt+u转换大小写
inoremap <c-u> <esc>bvE~ea
"转换首单词大小写
" inoremap <C-u> <esc>b~ea
" noremap fi :r !figlet
"z= 显示建议
"noremap <leader>sp :set spell!<CR>
" 去掉搜索高亮
"noremap <silent><F3> :nohls<CR>
"noremap <silent><space> :nohls<CR>
"set pastetoggle=<F2> "F2进入粘贴模式


" 代码折叠
nnoremap zo <Cmd>call VSCodeNotify('editor.unfold')<CR>
nnoremap zc <Cmd>call VSCodeNotify('editor.fold')<CR>
nnoremap za <Cmd>call VSCodeNotify('editor.toggleFold')<CR>


" 注释
nnoremap <LEADER>/ <Cmd>call VSCodeNotify('editor.action.commentLine')<CR>
vmap <LEADER>/ <Cmd>call VSCodeNotify('editor.action.commentLine')<CR><esc>


" 窗口
"调整分屏大小,ctrl+方向键调整大小
"noremap <C-up> :res +5<CR>
"noremap <C-down> :res -5<CR>
"noremap <C-left> :vertical resize-5<CR>
"noremap <C-right> :vertical resize+5<CR>
"切换窗口
map <Down> <C-W>j
map <Up> <C-W>k
map <Left> <C-W>h
map <Right> <C-W>l
" 切换窗口
map <leader>j <C-W>j
map <leader>k <C-W>k
map <leader>h <C-W>h
map <leader>l <C-W>l
" Place the two screens up and down
"noremap srh <C-w>t<C-w>K
" Place the two screens side by side
"noremap srv <C-w>t<C-w>H


"搜索结果居中展示
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * *zz
nnoremap <silent> # #zz
nnoremap <silent> g* g*zz


" 调整缩进后自动选中，方便再次操作
nnoremap < <<
nnoremap > >>
vnoremap < <gv
vnoremap > >gv

" 选中并高亮最后一次插入的内容
nnoremap gv `[v`]
" select block
nnoremap <leader>v V`}



" 跳转
nnoremap K <Cmd>call VSCodeNotify('editor.action.showHover')<CR>
nnoremap <leader>rn <Cmd>call VSCodeNotify('editor.action.rename')<CR>
" 转到定义
nnoremap gd <Cmd>call VSCodeNotify('editor.action.revealDefinition')<CR>
nnoremap gD <Cmd>call VSCodeNotify('editor.action.peekDefinition')<CR>
" 转到类型定义
nnoremap gy <Cmd>call VSCodeNotify('editor.action.goToTypeDefinition')<CR>
nnoremap gY <Cmd>call VSCodeNotify('editor.action.peekTypeDefinition')<CR>
" 转到实现
nnoremap gi <Cmd>call VSCodeNotify('editor.action.goToImplementation')<CR>
nnoremap gI <Cmd>call VSCodeNotify('editor.action.peekImplementation')<CR>
" nnoremap gr <Cmd>call VSCodeNotify('references-view.findReferences')<CR>
" 查看引用
nnoremap gr <Cmd>call VSCodeNotify('editor.action.goToReferences')<CR>
nnoremap gR <Cmd>call VSCodeNotify('editor.action.referenceSearch.trigger')<CR>
nnoremap tg <Cmd>call VSCodeNotify('workbench.action.gotoSymbol')<CR>



" 搜索
nnoremap <leader>tp <Cmd>call VSCodeNotify('projectManager.listProjects')<CR>
nnoremap <leader>f <Cmd>call VSCodeNotify('metaGo.gotoSmart')<CR>
nnoremap tr <Cmd>call VSCodeNotify('workbench.view.explorer')<CR>
nnoremap <c-f> <Cmd>call VSCodeNotify('workbench.view.search.focus')<CR>
nnoremap <c-l> <Cmd>call VSCodeNotify('actions.find')<CR>
nnoremap <c-t> <Cmd>call VSCodeNotify('workbench.files.action.focusOpenEditorsView')<CR>
nnoremap <c-s> <Cmd>call VSCodeNotify('workbench.action.openPreviousEditorFromHistory')<CR>
nnoremap <c-h> <Cmd>call VSCodeNotify('workbench.action.showCommands')<CR>
nnoremap <c-e> <Cmd>call VSCodeNotify('workbench.actions.view.problems')<CR>

" 错误
nnoremap ]e <Cmd>call VSCodeNotify('editor.action.marker.nextInFiles')<CR>
nnoremap [e <Cmd>call VSCodeNotify('editor.action.marker.prevInFiles')<CR>

" 格式化
"vnoremap <leader>fa <Cmd>call VSCodeNotifyVisual('editor.action.formatSelection', 0)<CR> <esc>
xnoremap <leader>fa <Cmd>lua require('vscode').call('editor.action.formatSelection')<CR> <esc>
" git
nnoremap ]g <Cmd>call VSCodeNotify('workbench.action.editor.nextChange')<CR>
nnoremap [g <Cmd>call VSCodeNotify('workbench.action.editor.previousChange')<CR>
nnoremap gl <Cmd>call VSCodeNotify('workbench.view.scm')<CR>


" 书签(Bookmarks扩展)
nnoremap mm <Cmd>call VSCodeNotify('bookmarks.toggle')<CR>
nnoremap mn <Cmd>call VSCodeNotify('bookmarks.jumpToNext')<CR>
nnoremap mp <Cmd>call VSCodeNotify('bookmarks.jumpToPrevious')<CR>
nnoremap ml <Cmd>call VSCodeNotify('bookmarks.list')<CR>
nnoremap mc <Cmd>call VSCodeNotify('bookmarks.clear')<CR>
nnoremap ma <Cmd>call VSCodeNotify('workbench.view.extension.bookmarks')<CR>
nnoremap mi <Cmd>call VSCodeNotify('bookmarks.toggleLabeled')<CR>


" 添加空行
nnoremap [<space>  :<c-u>put! =repeat(nr2char(10), v:count1)<cr>'[
nnoremap ]<space>  :<c-u>put =repeat(nr2char(10), v:count1)<cr>
"添加日期
imap <F3> <C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR>


" 普通模式下高亮当前行,插入模式不高亮
" set cursorline         " 高亮当前行
" set cursorcolumn       " 高亮当列行
" autocmd InsertLeave,WinEnter * set cursorline
" autocmd InsertEnter,WinLeave * set nocursorline
" autocmd InsertLeave,WinEnter * set cursorcolumn
" autocmd InsertEnter,WinLeave * set nocursorcolumn


"打开自动定位到最后编辑的位置
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif


"不自动添加成注释
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "no rm $"|endif|endif
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o

autocmd TextYankPost * if v:event.operator ==# 'y' | call system('/mnt/c/Windows/System32/clip.exe', @0) | endif

noremap <LEADER><LEADER> <Esc>/<++><CR>:nohlsearch<CR>c4l

source ~/.config/nvim/md-snippets.vim

source ~/.config/nvim/vscode/pluglists.vim

source ~/.config/nvim/vscode/plugsettings.vim

